home *** CD-ROM | disk | FTP | other *** search
/ ASME's Mechanical Engine…ing Toolkit 1997 December / ASME's Mechanical Engineering Toolkit 1997 December.iso / c_lang / shar.c < prev    next >
C/C++ Source or Header  |  1985-07-06  |  672b  |  29 lines

  1. /* make a shell archive out of the files passed as arguments */
  2. #include <stdio.h>
  3.  
  4. main(argc, argv)
  5. char **argv;{
  6.     int i, j;
  7.     FILE *fo, *fi;
  8.     if((fo=fopen("shar.out", "w")) == NULL){
  9.         printf("can't open file shar.out\n");
  10.         exit(1);
  11.     }
  12.     fprintf(fo, "#!/bin/sh\n");
  13.     while(++argv, --argc>0){
  14.         if((fi=fopen(*argv, "r")) == NULL){
  15.             printf("can't read file %s\n", *argv);
  16.         } else{
  17.             fprintf(fo, "echo extracting %s ...\ncat >%s <<xzyyz\n",
  18.               *argv, *argv);
  19.             while((i=getc(fi)) != EOF) putc(j=i, fo);
  20.             if(j != '\n') putc('\n', fo);
  21.             fclose(fi);
  22.             fprintf(fo, "xzyyz\n");
  23.         }
  24.     }
  25.     fprintf(fo, "echo done\n");
  26.     fclose(fo);
  27.     exit(0);
  28. }
  29.